package servlet;

import dao.EmpDao;
import org.apache.ibatis.session.SqlSession;
import util.SqlSessionFactoryUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
@WebServlet("/empdelete")
public class EmpDeleteServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        response.setContentType("application/json;charset=utf-8");
        int empno = Integer.parseInt(request.getParameter("empno"));
        SqlSession sqlSession = SqlSessionFactoryUtil.getSqlSession();
        EmpDao empDao = sqlSession.getMapper(EmpDao.class);
        int num =empDao.deleteEmpById(empno);
        System.out.println(num);
        PrintWriter out = response.getWriter();
        out.println(num);
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }
}
